import 'package:flutter/material.dart';

class TabControllerExample1 extends StatefulWidget {
  @override
  _TabControllerExample1State createState() => _TabControllerExample1State();
}

class _TabControllerExample1State extends State<TabControllerExample1>
    with TickerProviderStateMixin {
  final List<Tab> tabs = [
    Tab(text: "Tab1"),
    Tab(text: "Tab2"),
    Tab(text: "Tab3"),
    Tab(text: "Tab4"),
    Tab(text: "Tab5"),
    Tab(text: "Tab6"),
  ];

  TabController _tabController;

  @override
  void initState() {
    _tabController = TabController(length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("TabControllerExample"),
      ),
      drawer: Drawer(
        child: ListView(
          children: [
            ListTile(title: Text("menu1")),
            ListTile(title: Text("menu1")),
            ListTile(title: Text("menu2")),
          ],
        ),
      ),
      body: DefaultTabController(
          length: tabs.length,
          child: Column(
            children: [
              Container(
                color: Colors.red,
                child: TabBar(tabs: tabs),
              ),
              Expanded(
                flex: 1,
                child: TabBarView(
                  children: tabs.map((Tab e) {
                    return Center(child: Text("view:${e.text}"));
                  }).toList(),
                ),
              ),
            ],
          )),
    );
  }
}

/*
TabBarView(
          controller: _tabController,
          children: tabs.map((Tab e) {
            return Center(child: Text("view:${e.text}"));
          }).toList(),
        )
*/
